from driver import GPIO
import utime
from driver import TIMER

irq_times2=0    #中断计数

        
#按键回调中不能执行耗时操作，比如：time.sleep
def irq_handler2(data):
    global irq_times2
    irq_times2 += 1   

#使能di1
gpio_irq2 = GPIO()       #消抖时间，单位ms
gpio_irq2.open("di1")
gpio_irq2.on(irq_handler2)

def cb1(args):
    global irq_times2
    print("irq_times2",irq_times2)
    irq_times2=0


if __name__=='__main__':
    tim0=TIMER(0)
    tim0.open(period=1000, mode=TIMER.PERIODIC, callback=cb1)

    while True:
        #输出按键的读取数值                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
        utime.sleep(1)

